<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>7.8复选框的全选/全不选</title>
		<script>
			function checkAll(){
				var checked = document.getElementById("checkAll").checked;	//1.获取编号前面的复选框的选中状态
				var checkBoxs = document.getElementsByName("checkBox");		//2.获取下面所有的复选框
				for(var i=0; i<checkBoxs.length; i++){						//3.对获取的所有复选框进行遍历
					checkBoxs[i].checked=checked;							//4.拿到每一个复选框，并设置状态
				}
			}
		</script>
		
	</head>
	<body>
		<table border="1" width="500" height="50" align="center" >
			<thead>
				<tr>
					<td colspan="4">
						<input type="button" value="添加" />
						<input type="button" value="删除" />
					</td>
				</tr>
				<tr>
					<th><input type="checkbox" onclick="checkAll()" id="checkAll"/></th>
					<th>编号</th>
					<th>姓名</th>
					<th>年龄</th>
				</tr>
			</thead>
			<tbody>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>1</td>
					<td>张三</td>
					<td>22</td>
				</tr>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>2</td>
					<td>李四</td>
					<td>25</td>
				</tr>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>3</td>
					<td>王五</td>
					<td>27</td>
				</tr>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>4</td>
					<td>赵六</td>
					<td>29</td>
				</tr>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>5</td>
					<td>田七</td>
					<td>30</td>
				</tr>
				<tr >
					<td><input type="checkbox" name="checkBox"/></td>
					<td>6</td>
					<td>汾九</td>
					<td>20</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>
